package com.lry.basic.algorithm.common;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2020/1/4
 */
public class MergeTwoSortArr {
    public static void main(String[] args) {
        int[] nums1 = new int[]{4,5,6,0,0,0,0};
        int m = 3;
        int[] nums2 = new int[]{1,2,3,7};
        int n= 4;
        merge(nums1,m,nums2,n);

        for (int i:nums1) {
            System.out.println(i);
        }
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int p = m-- + n-- -1;

        while(m>=0&&n>=0){
            nums1[p--] = nums1[m]>nums2[n]?nums1[m--]:nums2[n--];
        }

        while(n>=0){
            nums1[p--] = nums2[n--];
        }

    }
}
